﻿using Microsoft.AspNetCore.Mvc;
using MyTodoApi.Context;
using MyTodoApi.Services;
using Shared.ToDo.Dtos;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace MyTodoApi.Controllers
{
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class ToDoController : Controller
    {
        private readonly IToDoService todoService;

        public ToDoController(IToDoService todoService)
        {
            this.todoService = todoService;
        }

        [HttpGet]
        public async Task<ApiResponse> GetByIdAsync(int id) => await todoService.GetById(id);

        [HttpGet]
        public async Task<ApiResponse> GetAllAsync() => await todoService.GetAsync();

        [HttpPost]
        public async Task<ApiResponse> AddAsync([FromBody] ToDoDto toDo) => await todoService.AddAsync(toDo);

        [HttpPost]
        public async Task<ApiResponse> UpdateAsync([FromBody] ToDoDto toDo) => await todoService.UpdateAsync(toDo);

        [HttpDelete]
        public async Task<ApiResponse> DeleteAsync(int id) => await todoService.Delete(id);

    }
}
